<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%   
String path = request.getContextPath();   
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";   
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<base href="<%=basePath%>">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<link href="themes/bootstrap/easyui.css" rel="stylesheet">
<link href="themes/icon.css" rel="stylesheet">
<script type="text/javascript" src="js/jquery-1.9.1.js"></script>
<script type="text/javascript" src="js/jquery.easyui.min.js"></script>
<script type="text/javascript" src="js/easyui-lang-zh_CN.js"></script>
<style type="text/css">
#search {
	margin-top: 20px;
}
#roleList {
	margin-top: 40px;
}
</style>
</head>

<script type="text/javascript">
$(function(){
	$('#dg').datagrid({    
	    url:'showRoles',
	    pagination:true,
	    rownumbers:true,
	    onClickRow:function(index, row){
	    	$(this).datagrid('unselectRow', index);
	    },
	    columns:[[    
	        {field:'',title:'',checkbox:true},    
	        {field:'roleName',title:'角色名',width:'10%'},    
	        {field:'roleFuncs',title:'功能',width:'75%'},
	        {field:'roleId',title:'操作',width:'10%',
	        	formatter: function(value,row,index){
	        		return "<button onclick='updatePermission("+value+")'>修改权限</button>";		
	        	}
	        }
	    ]]    
	});
	
	$("#updateRoleFunc").click(function(){
		var nodes = $("#show").tree('getChecked',['checked','indeterminate']);
		var funcs = new Array();
		$.each(nodes,function(k,v){
			funcs.push(v.id);
		});
		$.ajax({
			url:'updateRoleFunc',
			type:'post',
			data:{"roleFuncs":funcs,"roleId":$("#roleId").val()},
			traditional:true,
			dataType:'text',
			success:function(data){
				if (data == "0") {
					$.messager.confirm('提示','更新失败',function(r){    
					    if (r){    
					        
					    }    
					});
				} else {
					$.messager.confirm('提示','更新成功',function(r){    
					    if (r){    
					        
					    }    
					});
				}
			}
		});
	});
});
function updatePermission(data){
	$('#show').tree({    
	    url: 'getFuncByUid',
	    checkbox:true,
	    animate:true,
	    queryParams:{roleId:data} 
	});
	$("#roleId").val(data);
	$("#updatePanel").panel('open');
}
</script>
<body>
<div id="updatePanel" class="easyui-window" title="权限更改"     
        style="width:300px;height:300px;padding:10px;background:#fafafa;"   
        data-options="iconCls:'icon-save',collapsible:false,minimizable:false,maximizable:false,closed:true">   
    <input type="hidden" id="roleId"/>
    <ul id="show"></ul>
    <div>
    	<button id="updateRoleFunc">更新</button>
    </div>
</div>
<div id="search"></div>
<div id="roleList">
<table id="dg"></table>
</div>
</body>
</html>